<template>
  <div class="update-gender">
    <van-picker
      show-toolbar
      title="性别选择"
      :columns="columns"
      :default-index="value"
      @cancel="$emit('close')"
      @confirm="onConfirm"
      @change="onPickerChange"
    />
  </div>
</template>

<script>
// import { updateUserproFile } from "@/api/user";
import request from "@/utils/request";
export default {
  name: "UpdateGender",
  props: {
    value: Number,
    required: true,
  },
  data() {
    return {
      columns: ["男", "女"],
      localGender: this.value,
    };
  },
  methods: {
    onPickerChange(picker, value, index) {
      this.localGender = index;
      // console.log(this.localGender);
    },
    async onConfirm() {
      const localGender = this.localGender;
      // console.log(localGender);
      await request({
        method: "PATCH",
        url: "http://192.168.33.66:3001/user",
        data: {
          sex: localGender,
        },
      });
      this.$emit("input", localGender);
      this.$emit("close");
      this.$toast.success("更新成功！");
    },
  },
};
</script>

<style>
</style>